<template>
  <div class="container">
    <el-table
      style="text-align: center"
      :data="data"
      :max-height="maxHeight"
      border
      highlight-current-row
      v-loading="loading"
      :row-style="{
        height: height_size == 2 ? '50px' : '',
      }"
      :cell-style="{
        padding: height_size == 3 ? '0' : '',
      }"
      :row-class-name="
        ({ row, rowIndex }) => {
          row.index = rowIndex
        }
      "
      @row-click="
        (row) => {
          $emit('select_row', row)
        }
      "
    >
      <el-table-column type="index" label="序号" width="80px"></el-table-column>
      <template v-for="item in header_list" :key="item.prop">
        <el-table-column
          :label="item.label"
          :prop="item.prop"
          sortable
          v-if="item.showTable"
          :show-overflow-tooltip="item.show_overflow_tooltip"
        >
          <template #default="scope">
            <div v-if="item.options.length">
              <div v-for="item1 in item.options" :key="item1.value">
                <span v-if="item1.value == scope.row[item.prop]">{{
                  item1.label
                }}</span>
              </div>
            </div>
            <div v-if="item.is_time_stamp">
              {{ formatDate(parseInt(scope.row[item.prop]), 'yyyy-MM-dd') }}
            </div>
            <!-- 系统通知发送次数处理 -->
            <div v-if="item.prop == 'maxTimes'">
              {{ scope.row[item.prop] == 0 ? '不限' : scope.row[item.prop] }}
            </div>
          </template>
        </el-table-column>
      </template>
      <el-table-column
        label="操作"
        fixed="right"
        v-if="data?.length && data[0]?.btn_list.length"
        :width="data[0]?.btn_list.length * 40"
      >
        <template #default="scope">
          <div v-if="scope.row.isAdmin">超管</div>
          <div class="flex_cc">
            <div v-for="(item1,index) in (scope.row.btn_list as any)">
              <el-tooltip
                v-if="item1.has_role && item1.btn_show && item1.icon != ''"
                :content="item1.label"
                placement="bottom"
              >
                <svgBtn
                  :icon="item1.icon"
                  style="font-size: 20px; padding: 0 10px"
                  @click.stop="
                    $emit('edit_list', { item: scope.row, type: index + 1 })
                  "
                ></svgBtn>
              </el-tooltip>
              <el-button
                v-if="item1.has_role && item1.btn_show && item1.icon == ''"
                @click="
                  $emit('edit_list', { item: scope.row, type: index + 1 })
                "
                >{{ item1.label }}</el-button
              >
            </div>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { formatDate } from '@/utils/utils' // 权限校验
import { ref, toRefs } from 'vue'
import svgBtn from '@/components/svg_button.vue'
const props = defineProps({
  data: Array,
  maxHeight: Number,
  height_size: Number,
  loading: Boolean,
  header_list: Array,
})
const { data, maxHeight, height_size, loading, header_list } =
  toRefs<any>(props)
</script>

<style lang="scss" scoped></style>
